/*
 * @Author: zhang zhijiang 2824735304@qq.com
 * @Date: 2025-03-22 18:54:18
 * @LastEditors: zhang zhijiang 2824735304@qq.com
 * @LastEditTime: 2025-03-22 20:33:07
 * @FilePath: /linux/test_3_22/mythread.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include<iostream>
#include<pthread.h>
#include<unistd.h>
// #include"blockqueue.hpp"
using namespace std;
pthread_mutex_t  lock = PTHREAD_MUTEX_INITIALIZER; 
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
void * routine(void * argvs)
{
    int * i = static_cast<int*> (argvs);
    pthread_mutex_lock(&lock);
    while(1)
    {
        pthread_cond_wait(&cond,&lock);
        cout<<"thread-" <<i<<" is running"<<endl;
        //pthread_mutex_unlock(&lock);
    }
}
int main()
{
    for(int i = 0;i<4;i++)
    {
        pthread_t tid;
        pthread_create(&tid,nullptr,routine,(void*) i);
        //sleep(2);
    }
    while(1)
    {
        pthread_cond_signal(&cond);
        // pthread_cond_broadcast(&cond);

        sleep(2);
    }
    return 0;
}